//
//  JJTabBarController.m
//  testP
//
//  Created by 陈家将 on 16/7/14.
//  Copyright © 2016年 chenjiajiang. All rights reserved.
//

#import "JJTabBarController.h"
#import "JJNavigationController.h"
#import "JJOneViewController.h" 
#import "JJTwoViewController.h"
#import "JJThreeViewController.h"
#import "JJFourViewController.h"
#import "JJTabBar.h"

@interface JJTabBarController ()

@end

@implementation JJTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupAllChildVC];
    [self replaceSysTabBar];
    [self setupTabBarStyle];
}

- (void)setupTabBarStyle{
    //    获取全局TabBar上的按钮
    UITabBarItem *item = [UITabBarItem appearance];
    //设定文字属性 **可设定大小** 分层次越小,优先级越高
//    NSMutableDictionary *attS = [NSMutableDictionary dictionary];
//    attS[NSFontAttributeName] = [UIFont systemFontOfSize:14 weight:1];
//    attS[NSForegroundColorAttributeName]   =  [UIColor grayColor];
//    [item setTitleTextAttributes:attS forState:UIControlStateNormal];
//    
    NSMutableDictionary *attSS = [NSMutableDictionary dictionary];
    attSS[NSFontAttributeName] = [UIFont systemFontOfSize:14 weight:1];
    attSS[NSForegroundColorAttributeName]   =  [UIColor orangeColor];
    [item setTitleTextAttributes:attSS forState:UIControlStateSelected];
}
/** 设置所有子控制器 */
- (void)setupAllChildVC{
    
    [self setupOneChildVCWith:[[JJOneViewController alloc]init] title:@"我" image:@"tabBar_me_icon" selectImage:@"tabBar_me_click_icon"];
    [self setupOneChildVCWith:[[JJTwoViewController alloc]init] title:@"精华" image:@"tabBar_essence_icon" selectImage:@"tabBar_essence_click_icon"];
    [self setupOneChildVCWith:[[JJThreeViewController alloc]init] title:@"新帖" image:@"tabBar_new_icon" selectImage:@"tabBar_new_click_icon"];
    [self setupOneChildVCWith:[[JJFourViewController alloc]init] title:@"关注" image:@"tabBar_friendTrends_icon" selectImage:@"tabBar_friendTrends_click_icon"];
}
/** 设置一个控制器 */
- (void)setupOneChildVCWith:(UIViewController*)vc title:(NSString*)title image:(NSString*)name selectImage:(NSString*)selectName{
    vc.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:name];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectName];
    JJNavigationController *navVC = [[JJNavigationController alloc]initWithRootViewController:vc];
    [self addChildViewController:navVC];
}
/** 替换系统tabBar */
- (void)replaceSysTabBar{
    JJTabBar *bar = [[JJTabBar alloc]init];

    //kvc实现替换系统tabBar
    [self setValue:bar forKey:@"tabBar"];
}
@end
